package cn.xo68.boot.web;

import cn.xo68.boot.web.properties.WebCoreProperties;
import cn.xo68.boot.web.web.ReturnValueHandlerInitializingAdvice;
import cn.xo68.boot.web.web.StartupRuner;
import cn.xo68.boot.web.web.WebContext;
import cn.xo68.boot.web.web.exception.ErrorPageHandle;
import cn.xo68.boot.web.web.exception.ExceptionHandleController;
import cn.xo68.boot.web.web.filter.PrefixPathHandleFilter;
import cn.xo68.core.util.JsonUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

@Configuration
@EnableConfigurationProperties({WebCoreProperties.class})
@Import({
        ExceptionHandleController.class,
        ErrorPageHandle.class,
        PrefixPathHandleFilter.class,
        StartupRuner.class})
public class WebCoreAutoConfiguration {


    @ConditionalOnMissingBean
    @Bean
    public WebContext webContext(ApplicationContext applicationContext, JsonUtil jsonUtil){
        return new WebContext(applicationContext,jsonUtil);
    }
//    @Bean
//    public ErrorPageRegistrar errorPageRegistrar(WebCoreProperties webCoreProperties){
//        return new ErrorPageRegistrar() {
//            @Override
//            public void registerErrorPages(ErrorPageRegistry registry) {
//                ErrorPage errorPage=new ErrorPage(HttpStatus.NOT_FOUND, webCoreProperties.getErrorViewName());
//                registry.addErrorPages(errorPage);
//            }
//        };
//    }
}
